package com.A2yeild方法与join方法的区别;

/**
 * @Auther: SJZ    2907374717@qq.com
 * @Date: 2019/3/11 22:56
 * @Description:
 */
public class JoinExample {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("First task started");
                System.out.println("First task Sleeping for 2 seconds");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("First task completed");
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("Second task completed");
            }
        });
        t1.start();
        t1.join();//t1 执行完再执行t2
        t2.start();

    }
}
